package a2022.a20230109;

/**
 * @author lenovo
 * @date 2023/1/9
 */
public class a {
    public static void main(String[] args) {
//        System.out.println(reinitializePermutation(999));0
        System.out.println(reinitializePermutation2(999));
    }

    public static int reinitializePermutation(int n) {
        int i = 1, step = 1;
        while (true) {
            i = i % 2 == 0 ? i / 2 : (n - 1 + i) / 2;
            if (i == 1) return step;
            step++;
        }
    }

    public static int reinitializePermutation2(int n) {
        if (n == 2) {
            return 1;
        }
        int step = 1, pow2 = 2;
        while (pow2 != 1) {
            step++;
            pow2 = pow2 * 2 % (n - 1);
        }
        return step;
    }


}
